package cn.com.homeyoda.aimate.aihealth.ui.record;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.bean.VisualBean;

public class VisualRecordAdapter extends BaseQuickAdapter<VisualBean.DataBean, BaseViewHolder> {

    public VisualRecordAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, VisualBean.DataBean item) {
        int color = ContextCompat.getColor(mContext, helper.getLayoutPosition() % 2 == 0 ? R.color.clr_0065FF_6 : R.color.clr_0065FF_2);

        helper.setBackgroundColor(R.id.tv_heart_rate, color);
        helper.setBackgroundColor(R.id.tv_measure_time, color);

        int value = item.getValue();
        helper.setText(R.id.tv_heart_rate, String.valueOf(value));
        helper.setText(R.id.tv_measure_time, item.getAddTime());

        int textColor;
        if (value <= item.getValueMin()) {
            textColor = R.color.clr_2CB176;
        } else if (value >= item.getValueMax()) {
            textColor = R.color.clr_FF3333;
        } else {
            textColor = R.color.black_80;
        }
        helper.setTextColor(R.id.tv_heart_rate, ContextCompat.getColor(mContext, textColor));
    }

    @Override
    public void setNewData(@Nullable List<VisualBean.DataBean> data) {
        super.setNewData(data);
    }
}
